package com.wuseguang.springcloud.controller;


import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.entity.Exams;
import com.wuseguang.springcloud.service.ExamsService;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 考试表 前端控制器
 * </p>
 *
 * @author 
 * @since 2020-04-28
 */
@RestController
@RequestMapping("/exams")
public class ExamsController {

    private Logger logger = LoggerFactory.getLogger(this.toString());
    @Autowired
    private ExamsService examsServiceImpl;

    /**
     * 删除考试信息
     * @param request
     * @param id 考试id
     * @return
     */
    @RequestMapping("/deleteExamsById")
    public Result deleteExamsById(RequestParameterWrapper request, @RequestParam("id") Integer id){
        logger.info("删除考试");
        return examsServiceImpl.deleteExamsById(id);
    }


    /**
     * 添加考试
     * @param request
     * @param exams 考试信息
     * @return
     */
    @RequestMapping("/addExams")
    public Result addExams(RequestParameterWrapper request, Exams exams){
        logger.info("添加考试");
        //获取学校id
        String schoolId = request.getParam("schoolId");
        exams.setSchoolId(Integer.valueOf(schoolId));
        return examsServiceImpl.addExams(exams);
    }

    /**
     * 修改考试
     * @param request
     * @param exams 考试信息
     * @return
     */
    @RequestMapping("/updateExams")
    public Result updateExams(RequestParameterWrapper request,  Exams exams){
        logger.info("修改考试");
        return examsServiceImpl.updateExams(exams);
}

    /**
     * 根据考场查询考试信息
     * @param request
     * @param examinationRoomId 考场id
     * @param indexNo 页码
     * @param rows 每页显示数量
     * @return
     */
    @RequestMapping("/findExamsByExaminationRoomId")
    public Result findExamsByExaminationRoomId(RequestParameterWrapper request,
                            @RequestParam("examinationRoomId") Integer examinationRoomId,
                            @RequestParam(value = "indexNo", required = false, defaultValue = "1") Integer indexNo,
                            @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows){
        logger.info("根据考场查询考试信息");
        return examsServiceImpl.findExamsByExaminationRoomId( examinationRoomId,indexNo, rows);
    }


}

